/**
 * 
 */
package br.com.portal.fitness.dao;

import java.io.Serializable;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.transaction.annotation.Transactional;

/**
 * @author rjulio
 * @param <T>
 * @param <ID>
 *
 */

@Transactional
public abstract class GenericDAO<T, ID extends Serializable> implements Serializable, IGenericDAO<T, ID> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@PersistenceContext(unitName="portalPU")
	private EntityManager em;
	
//	@PersistenceUnit
//	public void setEmf(EntityManagerFactory emf) {
//		this.emf = emf;
//	}
	
	protected EntityManager getEntityManager(){
		return this.em;
	}

	@Override
	public T salva(T entity) {
		getEntityManager().persist(entity);
		return entity;
	}

	@Override
	public T atualiza(T entity) {
		return getEntityManager().merge(entity);
	}

	@Override
	public void exclui(T entity) {
		getEntityManager().remove(entity);
		
	}

	
	
	
	
	
	
	
}
